package com.testplatform.aitestplatform.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.testplatform.common.annotation.Log;
import com.testplatform.common.core.controller.BaseController;
import com.testplatform.common.core.domain.AjaxResult;
import com.testplatform.common.core.domain.R;
import com.testplatform.common.core.page.TableDataInfo;
import com.testplatform.common.enums.BusinessType;
import com.testplatform.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.testplatform.aitestplatform.domain.TestEnvironment;
import com.testplatform.aitestplatform.service.ITestEnvironmentService;


/**
 * DEV环境Controller
 * 
 * @author carrier
 * @date 2025-10-26
 */
@Api("DEV环境管理")
@RestController
@RequestMapping("/aitestplatform/environment")
public class TestEnvironmentController extends BaseController
{
    @Autowired
    private ITestEnvironmentService testEnvironmentService;

    /**
     * 查询DEV环境列表
     */
    @ApiOperation("查询DEV环境列表")
    @PreAuthorize("@ss.hasPermi('aitestplatform:environment:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam("查询条件对象") TestEnvironment testEnvironment)
    {
        startPage();
        List<TestEnvironment> list = testEnvironmentService.selectTestEnvironmentList(testEnvironment);
        return getDataTable(list);
    }

    /**
     * 导出DEV环境列表
     */
    @ApiOperation("导出DEV环境列表")
    @PreAuthorize("@ss.hasPermi('aitestplatform:environment:export')")
    @Log(title = "DEV环境", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam("导出的查询条件") HttpServletResponse response, TestEnvironment testEnvironment)
    {
        List<TestEnvironment> list = testEnvironmentService.selectTestEnvironmentList(testEnvironment);
        ExcelUtil<TestEnvironment> util = new ExcelUtil<TestEnvironment>(TestEnvironment.class);
        util.exportExcel(response, list, "DEV环境数据");
    }

    /**
     * 获取DEV环境详细信息
     */
    @ApiOperation("获取DEV环境详细信息")
    @PreAuthorize("@ss.hasPermi('aitestplatform:environment:query')")
    @GetMapping(value = "/{id}")
    public R<TestEnvironment> getInfo(@PathVariable("id") @ApiParam("DEV环境ID") Long id)
    {
        return R.ok(testEnvironmentService.selectTestEnvironmentById(id));
    }

    /**
     * 新增DEV环境
     */
    @ApiOperation("新增DEV环境")
    @PreAuthorize("@ss.hasPermi('aitestplatform:environment:add')")
    @Log(title = "DEV环境", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @ApiParam("新增的DEV环境对象") TestEnvironment testEnvironment)
    {
        return toAjax(testEnvironmentService.insertTestEnvironment(testEnvironment));
    }

    /**
     * 修改DEV环境
     */
    @ApiOperation("修改DEV环境")
    @PreAuthorize("@ss.hasPermi('aitestplatform:environment:edit')")
    @Log(title = "DEV环境", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @ApiParam("修改的DEV环境对象") TestEnvironment testEnvironment)
    {
        return toAjax(testEnvironmentService.updateTestEnvironment(testEnvironment));
    }

    /**
     * 删除DEV环境
     */
    @ApiOperation("删除DEV环境")
    @PreAuthorize("@ss.hasPermi('aitestplatform:environment:remove')")
    @Log(title = "DEV环境", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable @ApiParam("要删除的DEV环境ID") Long[] ids)
    {
        return toAjax(testEnvironmentService.deleteTestEnvironmentByIds(ids));
    }
}
